package com.ywqf_api.controller;

import com.ywqf_api.dto.exc.ClientExcution;
import com.ywqf_api.dto.exc.HouseExcution;
import com.ywqf_api.dto.exc.ToLoginExcution;
import com.ywqf_api.dto.in.HouseTypeDto;
import com.ywqf_api.enums.ClientEnum;
import com.ywqf_api.enums.HouseEnum;
import com.ywqf_api.enums.ToLoginEnum;
import com.ywqf_api.service.HouseNeedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Api(description="求租求购接口",produces="application/json")
@Controller
@RequestMapping("house")
public class HouseNeedController {
    @Autowired
    private HouseNeedService houseNeedService;

    /**
     * 查询求租所有码表
     * @return
     */
    @ApiOperation(value = "查询求购所有码表", httpMethod = "POST", notes = "查询求租所有码表")
    @RequestMapping(value = "/sellHouse",
            method = RequestMethod.POST)
    @ResponseBody
    public ToLoginExcution sellHouse(){
        Map sellHouse=houseNeedService.findSellHouse();
        return new ToLoginExcution(ToLoginEnum.SUCCESS,sellHouse);
    }

    /**
     * 查询求购所有码表
     * @return
     */
    @ApiOperation(value = "查询求租所有码表", httpMethod = "POST", notes = "查询求购所有码表")
    @RequestMapping(value = "/rentHouse",
            method = RequestMethod.POST)
    @ResponseBody
    public ToLoginExcution rentHouse(){
        Map rentHouse=houseNeedService.findRentHouse();
        return new ToLoginExcution(ToLoginEnum.SUCCESS,rentHouse);
    }

    /**
     * 新增求租接口
     * @param houseTypeDto
     * @return
     */
    @ApiOperation(value = "新增求租接口", httpMethod = "POST", notes = "新增求租接口")
    @RequestMapping(value = "/rentAddHouse",
            method = RequestMethod.POST)
    @ResponseBody
    public ClientExcution rentAddHouse(HouseTypeDto houseTypeDto){

        int rentAddHouse=houseNeedService.saveHouse(houseTypeDto);
        return new ClientExcution(ClientEnum.SUCCESS,rentAddHouse);
    }

    /**
     * 求购接口
     * @param houseTypeDto
     * @return
     */
    @ApiOperation(value = "求购接口", httpMethod = "POST", notes = "求购接口")
    @RequestMapping(value = "/buyHouse",
            method = RequestMethod.POST)
    @ResponseBody
    public ClientExcution buyHouse(HouseTypeDto houseTypeDto){

        int buyHouse=houseNeedService.buyHouse(houseTypeDto);
        return new ClientExcution(ClientEnum.SUCCESS,buyHouse);
    }

    /**
     * 评价接口
     * @param evalContent
     * @param evalDegree
     * @return
     */
    @ApiOperation(value = "评价接口", httpMethod = "POST", notes = "评价接口")
    @RequestMapping(value = "/updateEvaluate",
            method = RequestMethod.POST)
    @ResponseBody
    public HouseExcution updateEvaluate(int maintainId, String evalContent,int evalDegree){
        int updateEvaluate=houseNeedService.updateEvaluate(maintainId,evalContent,evalDegree);
        if (updateEvaluate>0){
            return new HouseExcution(HouseEnum.SUCCESS,null);
        }
            return new HouseExcution(HouseEnum.FILE,null);
    }

    /**
     * 个人卡券信息
     * @param cardId
     * @return
     */
    @RequestMapping(value = "/findHousekeepingCard",
            method = RequestMethod.POST)
    @ResponseBody
    public ClientExcution findHousekeepingCard(int cardId){
        Map findHousekeepingCard=houseNeedService.findHousekeepingCard(cardId);
        return new ClientExcution(ClientEnum.SUCCESS,findHousekeepingCard);
    }

    /**
     * 卡券信息列表查询
     * @return
     */
    @RequestMapping(value = "/findCardList",
            method = RequestMethod.POST)
    @ResponseBody
    public ClientExcution findCardList(int customerId){
        List findCardList=houseNeedService.findCardList(customerId);
        return new ClientExcution(ClientEnum.SUCCESS,findCardList);
    }
//    @RequestMapping(value = "/findRoleList",
//            method = RequestMethod.POST)
//    @ResponseBody
//    public ClientExcution findRoleList(){
//        ClientExcution findRoleList=houseNeedService.findRoleList();
//        return new ClientExcution(ClientEnum.FIND_SUCCESS,findRoleList);
//    }
}
